#!/bin/sh

echo "start install mangjingw"

install_root=/etc/mangjingw

if [ ! -d $install_root ]; then
	mkdir -p $install_root
else
	./site/bin/mjwd stop
	rm -rf $install_root/site
fi

cp -rf ./site $install_root

if [ -d './node' ]; then
	rm -rf $install_root/node
	cp -rf ./node $install_root
fi

cp -f uninstall.sh $install_root

#setting node evn
ln -snf $install_root/node/bin/node /usr/bin/node
ln -snf $install_root/node/bin/npm /usr/bin/npm
ln -snf $install_root/node/bin/phantomjs /usr/bin/phantomjs

#setting service script
ln -snf $install_root/site/bin/mjwd /usr/bin/mjwd

# init mysql
node $install_root/site/tool/createdb.js clean 
node $install_root/site/tool/createdb.js init

cat ./site/version

mjwd start

echo "install mangjingw completely"
